#include "PopupListView.h"
#include <QScrollBar>
#include <QDebug>

PopupListView::PopupListView()
{
    auto vertical = this->verticalScrollBar();
    connect(vertical, &QScrollBar::valueChanged, [this](){
        qDebug() << "value chagne";
        updateRange();
    });

    connect(vertical, &QScrollBar::rangeChanged, [this](){
        qDebug() << "range change";
        updateRange();
    });
}

void PopupListView::updateRange() {
    int begin = this->verticalScrollBar()->value();
    int end = this->verticalScrollBar()->pageStep() + begin + 1;
    emit viewChange(begin, end);
}

QSize PopupListView::sizeHint() const
{
    return QSize(0,0);
}

QSize PopupListView::minimumSizeHint() const
{
    return QSize(0,0);
}

void PopupListView::currentChanged(const QModelIndex &current, const QModelIndex &previous)
{
    qDebug() << "change" << current << previous;
    QListView::currentChanged(current,previous);
}

QModelIndexList PopupListView::selectedIndexes() const
{
    return QListView::selectedIndexes();
}
